function iforum_prefs() {
	this.prefBranch = null;

	this.PREF_PAGE_THREADCOUNT = "iforum.page.threadcount";
	this.initPrefs();
}

iforum_prefs.prototype.getPrefBranch = function() {
	if (!this.prefBranch) {
		this.prefBranch = Components.classes['@mozilla.org/preferences-service;1']
				.getService();
		this.prefBranch = this.prefBranch
				.QueryInterface(Components.interfaces.nsIPrefBranch);
	}

	return this.prefBranch;
}

iforum_prefs.prototype.setBoolPref = function(aName, aValue) {
	try {
		this.getPrefBranch().setBoolPref(aName, aValue);
	} catch (e) {
	}
}

iforum_prefs.prototype.getBoolPref = function(aName) {
	var rv = null;

	try {
		rv = this.getPrefBranch().getBoolPref(aName);
	} catch (e) {
	}

	return rv;
}

iforum_prefs.prototype.setIntPref = function(aName, aValue) {
	try {
		this.getPrefBranch().setIntPref(aName, aValue);
	} catch (e) {
	}
}

iforum_prefs.prototype.getIntPref = function(aName) {
	var rv = null;

	try {
		rv = this.getPrefBranch().getIntPref(aName);
	} catch (e) {
	}

	return rv;
}

iforum_prefs.prototype.setCharPref = function(aName, aValue) {
	this.getPrefBranch().setCharPref(aName, aValue);
}

iforum_prefs.prototype.getCharPref = function(aName) {
	var rv = null;

	try {
		rv = this.getPrefBranch().getCharPref(aName);
	} catch (e) {

	}

	return rv;
}

iforum_prefs.prototype.initPrefs = function() {
	// set prefs if they don't exit
	this.initPref(this.PREF_PAGE_THREADCOUNT, "int", 50);
}

iforum_prefs.prototype.initPref = function(aPrefName, aPrefType, aDefaultValue) {
	switch (aPrefType) {
		case "bool" :
			var prefExists = this.getBoolPref(aPrefName);
			if (prefExists == null)
				this.setBoolPref(aPrefName, aDefaultValue);
			break;

		case "int" :
			var prefExists = this.getIntPref(aPrefName);
			if (prefExists == null)
				this.setIntPref(aPrefName, aDefaultValue);
			break;

		case "char" :
			var prefExists = this.getCharPref(aPrefName);
			if (prefExists == null)
				this.setCharPref(aPrefName, aDefaultValue);
			break;
	}
}

iforum_prefs.prototype.clearPref = function(aPrefName) {
	var rv = null;

	try {
		rv = this.getPrefBranch().clearUserPref(aPrefName);
	} catch (e) {
	}

	return rv;
}
